#include <stdio.h>
#include <grp.h>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

#include <string>
#include <map>
#include <vector>
#include <iostream>
#include <istream>
#include <ostream>
#include <iterator>
#include <sstream>
#include <algorithm>

void tokenize(const std::string& data, std::vector<std::string>& tokens){
	/*
	std::string::size_type pos, prevPos = 0;
	while(true) {
		pos = data.find_first_of(":", prevPos);
		if(pos == std::string::npos) {
			pos = data.length();
			std::string value = std::string(data.data()+prevPos, pos-prevPos);
			std::transform(value.begin(), value.end(), value.begin(), ::toupper);	
			tokens.push_back(value);
			break;
		} else {
			std::string value = std::string(data.data()+prevPos, pos-prevPos);
			std::transform(value.begin(), value.end(), value.begin(), ::toupper);	
			tokens.push_back(value);
		}
		prevPos = pos + 1;
	}
	*/
	
		std::string::size_type pos, prevPos = 0;
	bool isEnd = false;
	do {
		pos = data.find_first_of(":", prevPos);
		if(pos == std::string::npos) {
			isEnd = true;
			pos = data.length();
		}
		std::string value = std::string(data.data()+prevPos, pos-prevPos);
		std::transform(value.begin(), value.end(), value.begin(), ::toupper);
		tokens.push_back(value);
		prevPos = pos + 1;

	} while(!isEnd);
}

int main (void) {
	std::string str = "The:quick and dirty:brown:fox";
	
	std::map<int, const char *> val;
	val[1] = "green";
	if(val[1] == NULL)
		std::cout << "Teacher nto fount" << std::endl;
		
	// construct a stream from the string
	std::stringstream strstr(str);

	/*
	  // use stream iterators to copy the stream to the vector as whitespace separated strings
	  std::istream_iterator<std::string> it(strstr);
	  std::istream_iterator<std::string> end;
	  std::vector<std::string> results(it, end);

	  // send the vector to stdout.
	  std::ostream_iterator<std::string> oit(std::cout);
	  std::copy(results.begin(), results.end(), oit);
	  return EXIT_SUCCESS;
	*/
	std::vector<std::string> results; std::string token;
/*	while(std::getline(strstr,token,':')) {
		results.push_back(token);
	} */
	tokenize(str,results);
	
	std::ostream_iterator<std::string> oit(std::cout);
	std::copy(results.begin(), results.end(), oit);
	  
	
	return EXIT_SUCCESS;
	
	uid_t me;
	struct passwd *my_passwd;
	struct group *my_group;
	char **members;

	/* Get information about the user ID.  */
	me = getuid ();
	my_passwd = getpwuid (me);
	if (!my_passwd) {
		printf ("Couldn't find out about user %d.\n", (int) me);
		exit (EXIT_FAILURE);
	}

	/* Print the information.  */
	printf ("I am %s.\n", my_passwd->pw_gecos);
	printf ("My login name is %s.\n", my_passwd->pw_name);
	printf ("My uid is %d.\n", (int) (my_passwd->pw_uid));
	printf ("My home directory is %s.\n", my_passwd->pw_dir);
	printf ("My default shell is %s.\n", my_passwd->pw_shell);

	/* Get information about the default group ID.  */
	my_group = getgrgid (my_passwd->pw_gid);
	if (!my_group) {
		printf ("Couldn't find out about group %d.\n", (int) my_passwd->pw_gid);
		exit (EXIT_FAILURE);
	}

	/* Print the information.  */
	printf ("My default group is %s (%d).\n",
	        my_group->gr_name, (int) (my_passwd->pw_gid));
	printf ("The members of this group are:\n");
	members = my_group->gr_mem;
	while (*members) {
		printf ("  %s\n", *(members));
		members++;
	}

	return EXIT_SUCCESS;
}
